package com.example.mobile2121606110syc0501homework;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tvMainTitle;
    private RecyclerView rvMainStudent;
    private List<Student> list = new ArrayList<>();
    private List<Student> list2 = new ArrayList<>();
    private Button btnMainStudent1;
    private Button btnMainStudent2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        list.add(new Student(1910605001, "小王", "女", "广东佛山"));
        list.add(new Student(1910605002, "小杨", "男", "广东阳江"));
        list.add(new Student(1910605003, "小吴", "女", "广东佛山"));
        list.add(new Student(1910605004, "小梁", "男", "广东广州"));
        list.add(new Student(1910605005, "小潘", "女", "广东佛山"));
        list.add(new Student(1910605006, "小杨", "男", "广东深圳"));
        list.add(new Student(1910605007, "小朱", "男", "广东佛山"));
        list2.add(new Student(1920605001, "小黄", "女", "广东清远"));
        list2.add(new Student(1920605002, "小陈", "男", "广东惠州"));
        list2.add(new Student(1920605003, "小张", "女", "广东佛山"));
        list2.add(new Student(1920605004, "小谢", "男", "广东云浮"));
        list2.add(new Student(1920605005, "小丁", "女", "广东佛山"));
        list2.add(new Student(1920605006, "小欧", "男", "广东珠海"));
        list2.add(new Student(1920605007, "小莫", "男", "广东佛山"));
        btnMainStudent1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StudentRViewAdapter adapter = new StudentRViewAdapter(list);
                rvMainStudent.setAdapter(adapter);
            }
        });
        btnMainStudent2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StudentRViewAdapter2 adapter = new StudentRViewAdapter2(list2);
                rvMainStudent.setAdapter(adapter);
            }
        });
        btnMainStudent2.setOnClickListener(this);
        rvMainStudent.setLayoutManager(new LinearLayoutManager(this));
        rvMainStudent.setAdapter(new StudentRViewAdapter(list));
        rvMainStudent.setAdapter(new StudentRViewAdapter2(list2));
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tvMainTitle);
        rvMainStudent = (RecyclerView) findViewById(R.id.rvMainStudent);
        btnMainStudent1 = (Button) findViewById(R.id.btnMainStudent1);
        btnMainStudent2 = (Button) findViewById(R.id.btnMainStudent2);
    }
    public void onClick(View view){
        Intent intent = new Intent();
        switch (view.getId()){
            case R.id.btnMainStudent1:
                intent.setClass(MainActivity.this,MainActivity.class);
                startActivity(intent);
                break;
            case R.id.btnMainStudent2:
                intent.setClass(MainActivity.this,MainActivity.class);
                startActivity(intent);
                break;
        }
    }
}